﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using MentorBackEnd.Business;
using MentorBackEnd.Model;

namespace WebApplication1
{
    public partial class Confirmation : System.Web.UI.Page
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            Repeater1.ItemDataBound += new RepeaterItemEventHandler(Repeater1_ItemDataBound);
        }

        void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.DataItem == null) return;

            Panel panel = (Panel)e.Item.FindControl("panelMessage");
            int id = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "SenderID"));
            if (panel != null)
                panel.CssClass += (id == 2) ? " mentor" : " mentee";
        }

        protected void Page_Load(object sender, EventArgs e)
        {

            List<Communication> messagehistory = CommunicationManager.GetCommunicationHistory(1, 2);
            Repeater1.DataSource = messagehistory;
            Repeater1.DataBind();

        }

        public void btnMessage_Click(Object sender, EventArgs e)
        {
            CommunicationManager.SendMessage(1, 2, txtMessage.Text, 1);
            txtMessage.Text = "";
            Page_Load(sender,  e);
        }
    }
}